package com.javasm.springmybatis.task;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

@Component
public class AsyncTask {
    private static final Logger LOG = LoggerFactory.getLogger(AsyncTask.class);

    @Async
    public void register() {
        LOG.info("多线程开始注册模拟");
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        LOG.info("多线程注册成功");
    }

    public Runnable ss(){
        return ()->{
            LOG.info("多线程开始注册模拟");
            try {
                Thread.sleep(2000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            LOG.info("多线程注册成功");
        };
    }

    @Async("asyncServiceExecutor")
    public void register2() {
        LOG.info("多线程开始注册模拟");
        try {
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        LOG.info("多线程注册成功");
    }
}
